/*******************************************************************************
 * Copyright (c) 2010 liw.
 * All rights reserved. 
 * 
 * This file is part of VanBus.
 * 
 *     VanBus is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     VanBus is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with VanBus.  If not, see <http://www.gnu.org/licenses/>.
 * Contributors:
 *     liw - initial API and implementation
 ******************************************************************************/
package org.niclab.vanbus.model;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class BusStop {
	
	private int dbId=0;
	private String stopId;
	private String stopName;
	private double latitude;
	private double longitude;
	private Map<BusRoute,List<String>> busTimes;
	private boolean favorite;
	private boolean closest; //transient
	private boolean refreshed; //transient
	public BusStop(){
		
	}
	
	public BusStop(String stopId){
		this.stopId = stopId;
	}
	
	public int getDbId(){
		return dbId;
	}
	public void setDbId(int id){
		this.dbId = id;
	
	}
	public boolean isRefreshed() {
		return refreshed;
	}

	public void setRefreshed(boolean refreshed) {
		this.refreshed = refreshed;
	}

	public String getStopId() {
		return stopId;
	}
	public void setStopId(String stopId) {
		this.stopId = stopId;
	}
	public String getStopName() {
		return stopName;
	}
	public void setStopName(String stopName) {
		this.stopName = stopName;
	}
	public double getLatitude() {
		return latitude;
	}
	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}
	public double getLongitude() {
		return longitude;
	}
	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public Map<BusRoute, List<String>> getBusTimes() {
		return busTimes;
	}

	public void setBusTimes(Map<BusRoute, List<String>> map) {
		this.busTimes = map;
	}
	
	public void putTimes(BusRoute route, List<String> times){
		if(busTimes == null)
			busTimes = new HashMap<BusRoute,List<String>>();
		busTimes.put(route, times);
		
	}
	
	public List<String> getTimes(BusRoute route){
		if (busTimes == null)
			return null;
		
		return busTimes.get(route);
	}
	
	public String getTimesString(BusRoute route){
		if(busTimes ==null)
			return null;
		
		List<String> times = busTimes.get(route);
		
		if (times.isEmpty())
			return "";
		
		StringBuilder str = new StringBuilder();
		
		for(String time:times){
			str.append(time);
			str.append(" ");
		}
		
		return str.toString();
		
	}

	public boolean isFavorite() {
		return favorite;
	}

	public void setFavorite(boolean favorite) {
		this.favorite = favorite;
	}

	public boolean isClosest() {
		return closest;
	}

	public void setClosest(boolean closest) {
		this.closest = closest;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((stopId == null) ? 0 : stopId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BusStop other = (BusStop) obj;
		if (stopId == null) {
			if (other.stopId != null)
				return false;
		} else if (!stopId.equals(other.stopId))
			return false;
		return true;
	}
	
	

}
